package infbmobile.pantallas;



import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.media.MediaException;
import javax.microedition.media.control.VideoControl;


class VideoCanvas extends Canvas implements CommandListener{
    private PantallaCamara form;
    private Command back;
    private Command capture;
    private VideoControl videoControl;





    public VideoCanvas(PantallaCamara form, VideoControl videoControl) {
       
        this.form = form;
        this.videoControl=videoControl;
        back = new Command("Salir", Command.BACK, 2);
        capture = new Command("Capturar", Command.SCREEN, 3);
        this.addCommand(back);
        this.addCommand(capture);
        this.setCommandListener(this);

       videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
    }

    public void empezar(){
            int width = getWidth();
            int height = getHeight();
            videoControl.setDisplayLocation(2, 2);
        try {
            videoControl.setDisplaySize(width - 4, height - 4);
        } catch (MediaException ex) {
            ex.printStackTrace();
        }
       
        videoControl.setVisible(true);
        Display d = Display.getDisplay(form.midlet);
        d.setCurrent(this);
    }

    public void paint(Graphics g) {
        int width = getWidth();
        int height = getHeight();

        g.setColor(255, 0, 0);
        g.drawRect(0, 0, width - 1, height - 1);
        g.drawRect(1, 1, width - 3, height - 3);
    }


    public void commandAction(Command c, Displayable d) {
         String label = c.getLabel();
        if (label.equals("Salir")) {
            form.player.close();
            form.midlet.salir();



        }else  {
            try {
                form.player.stop();
            } catch (MediaException ex) {
                ex.printStackTrace();
            }

            new Thread(){
                public void run (){
                    form.TomarFoto();
                }
            }.start();


           
           

        }
    }



}